package org.example.market_spring.service;

import org.example.market_spring.entity.Goods;
import org.example.market_spring.mapper.GoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class IndexService {
    @Autowired
    private GoodsMapper goodsMapper;

    //销售员从商品列表选择商品
    public List<Goods> goodsBySale(String id, String goodsName, String goodsType){
        Map<String, Object> params =new HashMap<>();
        params.put("id",id);
        params.put("goodsName",goodsName);
        params.put("goodsType",goodsType);
        return goodsMapper.goodsBySale(params);
    }

    //添加商品要销售的数量
    public void updateGoodsNum(String[] id,Goods goods){
        Map<String, Object> params = new HashMap<>();
        for(int i=0;i<id.length;i++){
            params.put("id",id[i]);
            params.put("saleNum",goods.getSaleNum());
            params.put("outNum",goods.getSaleNum());
            if(goods.getStoreNum() !=0){
                params.put("storeNum",goods.getStoreNum()-goods.getSaleNum());
            }
            params.put("cgNum",goods.getCgNum());
            goodsMapper.updateGoodsNum(params);
        }
    }

    //选择的商品显示到销售单列表中
    public List<Goods> querySaleTableData(String[] id){
        return goodsMapper.querySaleTableData(id);
    }

    public void  addSaleTicket(SaleTicket saleTicket){
        goodsMapper.addSaleTicket(saleTicket);
    }

    public List<SaleTicket> querySaleTicket(SaleTicket saleTicket){
        return goodsMapper.querySaleTicket(saleTicket);
    }

    public List<Goods> compareToSaleNumAndStoreNum(String[] id){
        return goodsMapper.compareToSaleNumAndStoreNum(id);
    }

    public List<Goods> queryOutTableData(String[] id){
        return goodsMapper.queryOutTableData(id);
    }

    public List<Goods> queryFaTicket(String[] id){
        return goodsMapper.queryFaTicket(id);
    }

    public List<Goods> queryGoodsStoreMsg(String id){
        return goodsMapper.queryGoodsStoreMsg(id);
    }

    public List<Goods> queryQHGoodsStoreMsg(Goods goods){
        return goodsMapper.queryQHGoodsStoreMsg(goods);
    }

    public List<Goods> queryBookStoreMsg(Goods goods){
        return goodsMapper.queryBookStoreMsg(goods);
    }

    public List<Goods> queryBookTicket(String[] id){
        return goodsMapper.queryBookTicket(id);
    }

    public List<Goods> queryIntoStoreMsg(Goods goods){
        return goodsMapper.queryIntoStoreMsg(goods);
    }

    public List<Goods> queryIntoTicket(String[] id){
        return goodsMapper.queryIntoTicket(id);
    }
}
